package com.kfm.hotel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.kfm.hotel.domain.IntakeInfo;
import com.kfm.hotel.mapper.IntakeInfoMapper;
import com.kfm.hotel.service.IntakeInfoService;
import com.kfm.hotel.service.RoomService;
import com.kfm.hotel.util.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
* @author Lenovo
* @description 针对表【intake_info】的数据库操作Service实现
* @createDate 2023-06-29 23:25:55
*/
@Service
public class IntakeInfoServiceImpl extends MPJBaseServiceImpl<IntakeInfoMapper, IntakeInfo>
    implements IntakeInfoService{
    @Autowired
    private RoomService roomService;
    @Transactional
    @Override
    public void checkIn(IntakeInfo intakeInfo) {
        save(intakeInfo);
         roomService.updateState(intakeInfo.getRoomId(), Constant.ROOM_STATE_CHECKIN);
    }

    @Override
    public PageInfo<IntakeInfo> listCheckOut(IntakeInfo entity, Integer page, Integer limit) {
        QueryWrapper<IntakeInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.isNull("exit_time");
        queryWrapper.eq("is_del",0);

        PageHelper.startPage(page,limit);
        List<IntakeInfo> list=listDeep(queryWrapper);
        return PageInfo.of(list);


    }

    @Override
    @Transactional
    public void checkOut(IntakeInfo intakeInfo, Integer opertorId) {
        intakeInfo.setExitTime(new Date());
        intakeInfo.setOperator(opertorId);
        intakeInfo.setUpdator(opertorId);

        //更新入住信息
        updateById(intakeInfo);
        //更新房间状态
        roomService.updateState(intakeInfo.getRoomId(),Constant.ROOM_STATE_TO_CLEAN);

    }


}




